package com.yhp.config;

import io.swagger.annotations.Api;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spi.service.contexts.ApiSelector;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class Swagger2 {
    //文档访问地址:http://localhost:端口号/swagger-ui.html    --springfox
    //文档访问地址:http://localhost:端口号/doc.html    --swagger-bootstrap-ui

    //配置swagger2核心配置docket
    @Bean
    public Docket createRestApi(){
        //指定api类型
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())//定义api总文档信息
                .select().apis(RequestHandlerSelectors.basePackage("com.yhp.web"))//扫描注解包
                .paths(PathSelectors.any())//所有的controller
                .build();

    }

    public ApiInfo apiInfo(){
        return  new ApiInfoBuilder().title("文档页标题")
                .contact(new Contact("文档创建人/联系人",
                        "http://www.yhp.com","594226632@qq.com"))
                .description("描述信息").version("文档版本1.0").termsOfServiceUrl("网站url:http://www.yhp.com").build();

    }




}
